import axios from 'axios'
import { CHANNEL_LIST } from '../constants/channels'

// !一般习惯在 action 里面做数据的整合操作（包括异步）
export const getChannelListAc = (payload) => ({
  type: CHANNEL_LIST,
  payload,
})

export const getChannelList = () => async (dispatch) => {
  // 发请求
  const {
    data: {
      data: { channels },
    },
  } = await axios.get('http://geek.itheima.net/v1_0/channels')
  dispatch(getChannelListAc(channels))
}
